//
//  HLTzidingyibangkaTableViewController.m
//  huiliantong
//
//  Created by hlt on 15/9/15.
//  Copyright (c) 2015年 hlt. All rights reserved.
//

#import "HLTzidingyibangkaTableViewController.h"

#import "HLTBandcardTableViewController.h"
@interface HLTzidingyibangkaTableViewController ()<MONActivityIndicatorViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *cardno;

@property (weak, nonatomic) IBOutlet UILabel *liushuihao;

@property (weak, nonatomic) IBOutlet UILabel *pwd;

@property (weak, nonatomic) IBOutlet UILabel *yzm;




@end

@implementation HLTzidingyibangkaTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.cardno.text=self.kahao;
//    self.liushuihao.text=self.liushuihao1;
    self.pwd.text=@"点击输入密码";
    
    
    UIView *view1=[[UIView alloc] initWithFrame:self.view.bounds];
    view1.backgroundColor=[UIColor grayColor];
    view1.alpha=0.4;
    [self.view addSubview:view1];
    MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
    indicatorView.delegate = self;
    indicatorView.numberOfCircles = 3;
    indicatorView.radius = 20;
    indicatorView.internalSpacing = 3;
    indicatorView.center = self.view.center;
    [indicatorView startAnimating];
    [self.view addSubview:indicatorView];
    
    
    //发送绑定卡得验证码
    
    Account *acc=[[AccountTool sharedAccountTool] currentAccount];
    NSString *url=[bangdingkayanzhengma stringByAppendingFormat:@"&user_name=%@&cardNum=%@",acc.custPhone,self.kahao];
    
    [HLTNetWorkingtool getdic:url success:^(NSDictionary *ary) {
        
        [indicatorView stopAnimating];
        [view1 removeFromSuperview];
        
        //将nsnumber 装换成nsstring
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString *str = [numberFormatter stringFromNumber:ary[@"code"]];
        if ([str isEqual:@"2"]) {
            
            NSLog(@"%@",ary[@"bandHuiRequestSvrTId"]);
            //重新赋值流水号
            self.liushuihao.text=ary[@"bandHuiRequestSvrTId"];
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"验证码短信已经发送"   message:ary[@"msg"]
                                                        delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            
            [alert show];
            
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"验证码短信发送失败"   message:ary[@"msg"]
                                                        delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            
            [alert show];
            
            
            [self.navigationController popViewControllerAnimated:YES];
            
            
        }
        
        
        
    } faliure:^(NSString *error) {
        
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"验证码短信发送失败"   message:nil
                                                    delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
        
        [alert show];
        
        [indicatorView stopAnimating];
        [view1 removeFromSuperview];
    }];

    
    
    
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        if (indexPath.row==2)
        {
            
            [EYInputPopupView popViewWithTitlenumber:@"填写卡密码(6位数)" contentText:@"请填写卡密码"
                                              type:EYInputPopupView_Type_single_line_text
                                       cancelBlock:^{
                                           
                                       } confirmBlock:^(UIView *view, NSString *text) {
                                           
                                           self.pwd.text=@"******";
                                           self.pwd1=text;
                                           //                                             self.newpwd.text=text;
                                       } dismissBlock:^{
                                           
                                       }];

            
        }
        else if (indexPath.row==3)
        {
            [EYInputPopupView popViewWithTitlechar:@"填写验证码" contentText:@"请填写验证码"
                                              type:EYInputPopupView_Type_single_line_text
                                       cancelBlock:^{
                                           
                                       } confirmBlock:^(UIView *view, NSString *text) {
                                           
                                           self.yzm.text=text;
                                           //                                             self.newpwd.text=text;
                                       } dismissBlock:^{
                                           
                                       }];
        }
    }
    
    
    
    
    
}










- (IBAction)tijiao:(id)sender {
    
    
    
    UIView *view1=[[UIView alloc] initWithFrame:self.view.bounds];
    view1.backgroundColor=[UIColor grayColor];
    view1.alpha=0.4;
    [self.view addSubview:view1];
    MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
    indicatorView.delegate = self;
    indicatorView.numberOfCircles = 3;
    indicatorView.radius = 20;
    indicatorView.internalSpacing = 3;
    indicatorView.center = self.view.center;
    [indicatorView startAnimating];
    [self.view addSubview:indicatorView];
    
    
    
    Account *acc=[[AccountTool sharedAccountTool] currentAccount];
    NSString *url=[querenbangding stringByAppendingFormat:@"&user_name=%@&cardNum=%@&password=%@&mobile_code=%@&transactionid=%@",acc.custPhone,self.kahao,self.pwd1,self.yzm.text,self.liushuihao.text];
    
    [HLTNetWorkingtool getdic:url success:^(NSDictionary *ary) {
       
        
        //将nsnumber 装换成nsstring
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString *str = [numberFormatter stringFromNumber:ary[@"code"]];
        if ([str isEqual:@"2"]) {
            
            NSString *url=[chaxunyue stringByAppendingFormat:@"&user_name=%@&cardNum=%@",acc.custPhone,self.kahao];
            [HLTNetWorkingtool getdic:url success:^(NSDictionary *ary) {
                [indicatorView stopAnimating];
                [view1 removeFromSuperview];
                
                NSDictionary *mydic=ary;
                if ([ary[@"status"] isEqual:@"0"]) {
                    //                    Account *acc=[[AccountTool sharedAccountTool] currentAccount];
                    //
                    acc.cardNo=self.kahao;
                    acc.YKTCardBalance=ary[@"deposit"];
                    [[AccountTool sharedAccountTool] addAccounts:acc];
                    NSLog(@"%@",ary);
                    [self.navigationController popViewControllerAnimated:YES];
                    [indicatorView stopAnimating];
                    [view1 removeFromSuperview];
                    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"绑定卡成功"   message:mydic[@"msg"]
                                                                delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                    
                    [alert show];
                    
                    
                    //返回到指定的控制器
                    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
                    
                }
            } faliure:^(NSString *error) {
                [indicatorView stopAnimating];
                [view1 removeFromSuperview];
                
            }];
            
            //
//                        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
            
//            [self.navigationController popViewControllerAnimated:YES]; //返回上一页面
            
        }
        else
        {
            
            [indicatorView stopAnimating];
            [view1 removeFromSuperview];
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"绑定卡失败"   message:ary[@"msg"]
                                                        delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            
            [alert show];
            
        }
        
        
        
    } faliure:^(NSString *error) {
        [indicatorView stopAnimating];
        [view1 removeFromSuperview];
    }];
    
    
    
}



//这个是回调方法
#pragma mark - MONActivityIndicatorViewDelegate Methods

- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView
      circleBackgroundColorAtIndex:(NSUInteger)index {
    CGFloat red   = (arc4random() % 256)/255.0;
    CGFloat green = (arc4random() % 256)/255.0;
    CGFloat blue  = (arc4random() % 256)/255.0;
    CGFloat alpha = 1.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}







@end
